package com.example.yls.demoa;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button bt1;
    private Button bt2;
    private Button bt3;
    private Button bt4;
    private Button bt5;
    private Button load;
    private SoundPool soundPool;
    private int[]soundIdArr = new int[5];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findview();

        load.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC,1);
                soundIdArr[0] = soundPool.load(MainActivity.this,R.raw.chimes,1);
                soundIdArr[1] = soundPool.load(MainActivity.this,R.raw.ding,1);
                soundIdArr[2] = soundPool.load(MainActivity.this,R.raw.enter,1);
                soundIdArr[3] = soundPool.load(MainActivity.this,R.raw.notify,1);
                soundIdArr[4] = soundPool.load(MainActivity.this,R.raw.ringout,1);
            }
        });
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[0],1,1,0,0,1);
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[1],1,1,0,0,1);
            }
        });
        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[2],1,1,0,0,1);
            }
        });
        bt4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[3],1,1,0,0,1);
            }
        });
        bt5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundIdArr[4],1,1,0,0,1);
            }
        });
    }


    private void findview() {
        bt1=findViewById(R.id.bt1);
        bt2=findViewById(R.id.bt2);
        bt3=findViewById(R.id.bt3);
        bt4=findViewById(R.id.bt4);
        bt5=findViewById(R.id.bt5);
        load=findViewById(R.id.load);
    }
}
